package com.lucas.servlet.chapter3_3.mapper;

import com.lucas.servlet.chapter3_3.entity.Student;
import org.apache.ibatis.annotations.*;

import javax.smartcardio.Card;
import java.util.List;

@Mapper
public interface StuMapper {
    //通过名字进行模糊查询
    @Select("select *from student where student_name like concat('%', #{name}, '%') ")  //模糊查询
    List<Student> getStuByName(String student_name);

    //一对一关联查询，在MyBatis中使用注解@One进行关联查询
    @Result(property = "card", column = "no", one = @One(select = "com.lucas.servlet.chapter3_3.mapper.StuMapper.getCardByNo"))   //注意用双引号

    @Select(("select *from student where qq=#{qq}"))
    List<Student> getStuByQQ(String qq);

    @Select("select  *from card where cardNo =#{no}")
    Card getCardByNo(String no);

    //动态sql语句
    @Select({
            "<script>",
            "select * from student where 1=1",
            "<if test='student_name!=null'>",
            "and student_name = #{student_name}",
            "</if>",
            "<if test='no!=null'>",
            "and no=#{no}",
            "</if>",
            "</script>"
    })

    //自动映射失败，显示找不到，智能使用@Param手动映射
    List<Student> getStuByNameOrNo(@Param("student_name")String student_name, @Param("no")String no);

}
